#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys


class DigiClock(QLCDNumber):
    def __init__(self, parent=None):
        super(DigiClock, self).__init__(parent)
        self.setDigitCount(8)

        p = self.palette()
        p.setColor(QPalette.Window, Qt.blue)
        self.setPalette(p)

        self.dragPosition = None
        # Qt.Qt.SplashScreen
        # self.setWindowFlags(Qt.FramelessWindowHint)|Qt.ToolTip
        self.setWindowFlags(Qt.WindowStaysOnTopHint|Qt.FramelessWindowHint)
        self.setWindowOpacity(0.5)

        timer = QTimer(self)
        self.connect(timer, SIGNAL("timeout()"), self.showTime)
        timer.start(1000)

        # self.showColon = True
        self.showTime()
        self.resize(150, 60)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
            event.accept()
        if event.button() == Qt.RightButton:
            self.close()

    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)
            event.accept()

    def showTime(self):
        time = QTime.currentTime()
        text = time.toString("hh:mm:ss")
        # if self.showColon:
        # text.replace(2,1,":")
        #     self.showColon=False
        # else:
        #     text.replace(2,1," ")
        #     self.showColon=True
        self.display(text)


app = QApplication(sys.argv)
form = DigiClock()
form.show()
app.exec_()